<template>
	<view>
		<view class="wrap">
			<view style="background-color: #fff;border-radius: 16rpx;padding: 30rpx;">
				<u-form :model="model" :rules="rules" ref="uForm" :errorType="errorType" :border-bottom="false">
					<u-form-item :label-position="labelPosition" prop="photo" label-width="150" :border-bottom="false">
						<view class="" style=" width: 100% ;display: flex;flex-direction: row;justify-content: center;">
							<u-upload max-count="1" width="200" @on-success="fileSuccess" @on-remove="fileRemove"
								height="200" :header="{'token':token}" :action="action" :file-list="fileList"
								:size-type="['compressed']" upload-text="选择图片" :multiple="false"></u-upload>
						</view>
					</u-form-item>
				</u-form>
			</view>
			<view style="margin-top: 50rpx;">
				<u-button @click="submit" type="primary">提交</u-button>
			</view>
		</view>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	export default {
		data() {
			return {

				model: {
					logoPath: ''
				},
				labelPosition: 'left',
				errorType: ['toast'],
				action: this.sysConstant.FILE_SRC_UPLOAD,
				fileList: [],
				sysConstant: this.sysConstant.FILE_SRC_PATH,
				token: getApp().globalData.token,

			}
		},
		onLoad(e) {
			this.fileList = [{
				url: this.sysConstant + e.logoPath
			}]
		},
		methods: {
		
				fileSuccess(data, index, lists, name) {
					console.log(data)
					this.model.logoPath = data.data.path
				},
		
			submit(){
				this.$u.put('/life/shop/update', {
					logoPath: this.model.logoPath
				}).then(res => {
					console.log(res)
					if (res.success) {
						this.$refs.uToast.show({
							title: '修改成功',
							type: 'success',
						})
						setTimeout(()=>{
							uni.navigateBack({
								delta:1
							})
						},1000)
						
					} else {
						this.$refs.uToast.show({
							title: res.msg,
							type: 'error',
						})
					}
				}).catch(() => {
					this.$refs.uToast.show({
						title: "请求失败",
						type: 'error',
					})
				})
			},
		}
	}
</script>

<style>

</style>